package com.zac.coroutine.algorithm.leetcode

import com.zac.coroutine.algorithm.leetcode.linkedlist.ListNode

/**
 * author zac
 * date 2025/8/4
 *
 */
object TestUtils {


    fun IntArray?.print() {
        if (this == null) {
            print("the arr is null")
        }
        print("[")
        this?.forEach {
            print("$it,")
        }
        print("]")
    }

    fun IntArray.makeListNode(): ListNode? {
        var last: ListNode? = null
        var head: ListNode? = null
        for (i in 0 until this.size) {
            val cur = ListNode(null, this[i])
            if (i != 0) {
                last?.next = cur
            } else {
                head = cur
            }
            last = cur
        }
        println("generated linked list:")
        var a = head
        print("[")
        while (true) {
            print("${a!!.`val`}")
            a = a.next
            if (a == null) {
                break
            }
            print(",")
        }
        println("]")
        return head
    }


}